Source data: https://covidtracking.com/, which updates daily at 4 PM ET.

US

Row

Cumulative Cases

Note that total cases are plotted on a log scale.

New Daily Cases

The 5-day rolling average is plotted.

Row

Daily Growth Factor

This is the factor by which new cases multiply each day. A growth factor less than 1 indicates declining growth. A growth factor greater than 1 indicates increasing, and possibly exponential, growth. The 5-day rolling average is plotted.

Percent Change in New Cases

Percent change is calculated as using the 5-day rolling average of daily new cases as a percent of total cases for that day. Only dates with more than 10 total cases are plotted.

WI

Row

Cumulative Cases

Note that total cases are plotted on a log scale.

New Daily Cases

The 5-day rolling average is plotted.

Row

Daily Growth Factor

This is the factor by which new cases multiply each day. A growth factor less than 1 indicates declining growth. A growth factor greater than 1 indicates increasing, and possibly exponential, growth. The 5-day rolling average is plotted.

Percent Change in New Cases

Percent change is calculated as using the 5-day rolling average of daily new cases as a percent of total cases for that day. Only dates with more than 10 total cases are plotted.

MN

Row

Cumulative Cases

Note that total cases are plotted on a log scale.

New Daily Cases

The 5-day rolling average is plotted.

Row

Daily Growth Factor

This is the factor by which new cases multiply each day. A growth factor less than 1 indicates declining growth. A growth factor greater than 1 indicates increasing, and possibly exponential, growth. The 5-day rolling average is plotted.

Percent Change in New Cases

Percent change is calculated as using the 5-day rolling average of daily new cases as a percent of total cases for that day. Only dates with more than 10 total cases are plotted.

AL

Row

Cumulative Cases

Note that total cases are plotted on a log scale.

New Daily Cases

The 5-day rolling average is plotted.

Row

Daily Growth Factor

This is the factor by which new cases multiply each day. A growth factor less than 1 indicates declining growth. A growth factor greater than 1 indicates increasing, and possibly exponential, growth. The 5-day rolling average is plotted.

Percent Change in New Cases

Percent change is calculated as using the 5-day rolling average of daily new cases as a percent of total cases for that day. Only dates with more than 10 total cases are plotted.

MA

Row

Cumulative Cases

Note that total cases are plotted on a log scale.

New Daily Cases

The 5-day rolling average is plotted.

Row

Daily Growth Factor

This is the factor by which new cases multiply each day. A growth factor less than 1 indicates declining growth. A growth factor greater than 1 indicates increasing, and possibly exponential, growth. The 5-day rolling average is plotted.

Percent Change in New Cases

Percent change is calculated as using the 5-day rolling average of daily new cases as a percent of total cases for that day. Only dates with more than 10 total cases are plotted.

NJ

Row

Cumulative Cases

Note that total cases are plotted on a log scale.

New Daily Cases

The 5-day rolling average is plotted.

Row

Daily Growth Factor

This is the factor by which new cases multiply each day. A growth factor less than 1 indicates declining growth. A growth factor greater than 1 indicates increasing, and possibly exponential, growth. The 5-day rolling average is plotted.

Percent Change in New Cases

Percent change is calculated as using the 5-day rolling average of daily new cases as a percent of total cases for that day. Only dates with more than 10 total cases are plotted.

---
title: "COVID Case Plots"
author: "John May"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: scroll
    source_code: embed
---

Source data: , which updates daily at 4 PM ET.

```{r setup, include=FALSE}
knitr::opts_chunk$set(
	echo = FALSE,
	message = FALSE,
	warning = FALSE
)
library(tidyverse)
library(jsonlite)
library(lubridate)
library(httr)
library(scales)
library(plotly)
library(flexdashboard)
```
```{r importData, echo = FALSE}
COVID_states <- fromJSON("https://covidtracking.com/api/states/daily")
COVID_states$date <- ymd(COVID_states$date)
COVID_states <- COVID_states %>%
  arrange(date)

COVID_US <- fromJSON("https://covidtracking.com/api/us/daily")
COVID_US$date <- ymd(COVID_US$date)
COVID_US <- COVID_US %>%
  arrange(date)
```
```{r UScalcs, echo = FALSE}
COVID_US <- COVID_US %>%
  mutate(dailyPositives = c(NA, diff(positive)))

COVID_US <- COVID_US %>%
  mutate(growthRate = dailyPositives/lag(dailyPositives))

# calculate 5-day averaged new cases
COVID_US <- COVID_US %>%
  mutate(avgDailyPositives = 
           (lag(dailyPositives, n = 2) +
            lag(dailyPositives, n = 1) +
              dailyPositives +
              lead(dailyPositives, n = 1) + 
              lead(dailyPositives, n = 2)) / 5)

# calculate 5-day averaged growth rate
COVID_US <- COVID_US %>%
  mutate(avgDailyGrowth = 
           (lag(growthRate, n = 2) +
              lag(growthRate, n = 1) +
              growthRate +
              lead(growthRate, n = 1) + 
              lead(growthRate, n = 2)) / 5 )

# calculate daily % change in average daily increase
COVID_US <- COVID_US %>%
  mutate(percentChange = 100 * avgDailyPositives / positive)
```

US
=================================================

Row 
---------------------------------------------------

### Cumulative Cases 

```{r UStotal, echo=FALSE}
US_total_plot <- ggplot(COVID_US,
                        aes(x = date, y = positive)) + 
  geom_line(color = "blue") +
  geom_point(fill = "gray25", size = rel(2)) + 
  scale_y_log10(breaks = log_breaks(n = 7, base = 10),
                limits = c(1, 10 * max(COVID_US$positive)), 
                labels = scales::comma_format(accuracy = 1),
                expand = c(0, 0)) + 
  scale_x_date(date_breaks = "1 week", 
               minor_breaks = "1 day", date_labels = "%b %d") + 
  xlab("Date") + 
  ylab("Total Confirmed Cases")

US_plotly_total <- ggplotly(p = (US_total_plot + theme_classic(base_size = 15) + 
  theme(panel.grid.major.y = element_line(color = "gray80"))))

US_plotly_total
```

> Note that total cases are plotted on a log scale.

### New Daily Cases

```{r USdaily, echo=FALSE}
# average new daily cases
US_new_daily_plot <- ggplot(COVID_US,
                            aes(x = date, y = avgDailyPositives)) +
  geom_col(color = "black", fill = "gray50") + 
  scale_y_continuous(labels = comma,
                     limits = c(0, 42000),
                     expand = c(0, 0)) +
  scale_x_date(date_breaks = "1 week", date_labels = "%b %d",
               minor_breaks = "1 day") +
  xlab("Date") + 
  ylab("Daily New Cases")

US_plotly_new_daily <- ggplotly(
  p = (US_new_daily_plot + 
         theme_classic(base_size = 15) + 
         theme(panel.grid.major.y = element_line(color = "gray85"))))

US_plotly_new_daily

```

> The 5-day rolling average is plotted.

Row
--------------------------------------------------

### Daily Growth Factor 

```{r USdailyGrowth, echo=FALSE}
US_growth_rate_plot <- ggplot(COVID_US,
                              aes(x = date, y = avgDailyGrowth)) +
  geom_line(color = "blue") +
  geom_point(fill = "gray25", size = rel(2)) + 
  scale_x_date(date_breaks = "1 week", 
               minor_breaks = "1 day", date_labels = "%b %d") + 
  scale_y_continuous(breaks = seq(0, round(1.5* max(COVID_US$avgDailyGrowth,
                                                    na.rm = TRUE), 
                                        digits = 0), by = 0.5),
                     limits = c(0, 1.5 * max(COVID_US$avgDailyGrowth, 
                                             na.rm = TRUE)),
                     expand = c(0, 0)) +
  xlab("Date") + 
  ylab("Daily Growth Factor")

US_growth_plotly <- ggplotly(
  p = (US_growth_rate_plot + theme_classic(base_size = 15) +
  theme(panel.grid.major.y = element_line(color = "gray80"))))

US_growth_plotly
```

> This is the factor by which new cases multiply each day. A growth factor less than 1 indicates declining growth. A growth factor greater than 1 indicates increasing, and possibly exponential, growth. The 5-day rolling average is plotted. 

### Percent Change in New Cases

```{r USpercentChange, echo=FALSE}
# average daily percent change
US_daily_percent <- COVID_US %>%
  filter(positive > 10) %>%
  ggplot(aes(x = date, y = percentChange)) +
  geom_col(color = "black", fill = "gray50") + 
  scale_y_continuous(labels = comma, limits = c(-25, 100),
                     expand = c(0, 0)) +
  scale_x_date(date_breaks = "1 week", date_labels = "%b %d",
               minor_breaks = "1 day") +
  xlab("Date") + 
  ylab("Percent change in cases")

USpercentPlot <- ggplotly(
  p = (
    US_daily_percent + theme_classic(base_size = 15) + 
      theme(panel.grid.major.y = element_line(color = "gray85"))))

USpercentPlot
```

> Percent change is calculated as using the 5-day rolling average of daily new cases as a percent of total cases for that day. Only dates with more than 10 total cases are plotted.

```{r stateDataCalcs, message=FALSE, warning=FALSE, include=FALSE}
# calculate daily increase of positive cases, averaged daily increase, and averaged daily growth rate by state

COVID_states <- COVID_states %>%
  group_by(state) %>%
  mutate(dailyPositives = c(NA, diff(positive)))

COVID_states <- COVID_states %>%
  group_by(state) %>%
  mutate(growthRate = dailyPositives/lag(dailyPositives))

# calculate 5-day averaged new cases
COVID_states <- COVID_states %>%
  group_by(state) %>%
  mutate(avgDailyPositives = 
           (lag(dailyPositives, n = 2) +
            lag(dailyPositives, n = 1) +
              dailyPositives +
              lead(dailyPositives, n = 1) + 
              lead(dailyPositives, n = 2)) / 5)

# calculate 5-day averaged growth rate
COVID_states <- COVID_states %>%
  group_by(state) %>%
  mutate(avgDailyGrowth = 
           (lag(growthRate, n = 2) +
              lag(growthRate, n = 1) +
              growthRate +
              lead(growthRate, n = 1) + 
              lead(growthRate, n = 2)) / 5 )
COVID_states <- COVID_states %>%
  group_by(state) %>%
    mutate(percentChange = 100 * avgDailyPositives / positive)
```

WI
==========================================

Row 
---------------------------------------------------

### Cumulative Cases 

```{r WItotal, echo=FALSE}
WI_total_plot <- COVID_states %>%
  filter(state %in% "WI") %>%
  ggplot(aes(x = date, y = positive)) + 
  geom_line(color = "blue") +
  geom_point(fill = "gray25", size = rel(2)) + 
  scale_y_log10(breaks = log_breaks(n = 7, base = 10),
                limits = c(1, 20000), 
                labels = scales::comma_format(accuracy = 1),
                expand = c(0, 0)) + 
  scale_x_date(date_breaks = "1 week", 
               minor_breaks = "1 day", date_labels = "%b %d") + 
  xlab("Date") + 
  ylab("Total Confirmed Cases")

WI_plotly_total <- ggplotly(p = (WI_total_plot + theme_classic(base_size = 15) + 
  theme(panel.grid.major.y = element_line(color = "gray80"))))

WI_plotly_total
```

> Note that total cases are plotted on a log scale.

### New Daily Cases

```{r WIdaily, echo=FALSE}
# average new daily cases
WI_new_daily_plot <- COVID_states %>%
  filter(state %in% "WI") %>%
  ggplot(aes(x = date, y = avgDailyPositives)) +
  geom_col(color = "black", fill = "gray50") + 
  scale_y_continuous(labels = comma,
                     limits = c(0, 300),
                     expand = c(0, 0)) +
  scale_x_date(date_breaks = "1 week", date_labels = "%b %d",
               minor_breaks = "1 day") +
  xlab("Date") + 
  ylab("Daily New Cases")

WI_plotly_new_daily <- ggplotly(
  p = (WI_new_daily_plot + 
         theme_classic(base_size = 15) + 
         theme(panel.grid.major.y = element_line(color = "gray85"))))

WI_plotly_new_daily
```

> The 5-day rolling average is plotted.

Row
--------------------------------------------------

### Daily Growth Factor 

```{r WIdailyGrowth, echo=FALSE}
WI_growth_rate_plot <- COVID_states %>%
  filter(state %in% "WI") %>%
  filter(avgDailyGrowth < 100) %>%
  ggplot(aes(x = date, y = avgDailyGrowth)) +
  geom_line(color = "blue") +
  geom_point(fill = "gray25", size = rel(2)) + 
  scale_x_date(date_breaks = "1 week", 
               minor_breaks = "1 day", date_labels = "%b %d") + 
  scale_y_continuous(breaks = seq(0, 2.5, by = 0.5),
                     limits = c(0, 2.6),
                     expand = c(0, 0)) +
  xlab("Date") + 
  ylab("Daily Growth Factor")

WI_growth_plotly <- ggplotly(
  p = (WI_growth_rate_plot + theme_classic(base_size = 15) +
  theme(panel.grid.major.y = element_line(color = "gray80"))))

WI_growth_plotly
```

> This is the factor by which new cases multiply each day. A growth factor less than 1 indicates declining growth. A growth factor greater than 1 indicates increasing, and possibly exponential, growth. The 5-day rolling average is plotted. 

### Percent Change in New Cases

```{r WIpercentChange, echo=FALSE}
# average daily percent change
WI_daily_percent <- COVID_states %>%
  filter(state %in% "WI") %>%
  filter(positive > 10) %>%
  ggplot(aes(x = date, y = percentChange)) +
  geom_col(color = "black", fill = "gray50") + 
  scale_y_continuous(labels = comma, limits = c(-25, 100),
                     expand = c(0, 0)) +
  scale_x_date(date_breaks = "1 week", date_labels = "%b %d",
               minor_breaks = "1 day") +
  xlab("Date") + 
  ylab("Percent change in cases")

WIpercentPlotly <- ggplotly(
  p = (
    WI_daily_percent + theme_classic(base_size = 15) + 
      theme(panel.grid.major.y = element_line(color = "gray85"))))

WIpercentPlotly
```

> Percent change is calculated as using the 5-day rolling average of daily new cases as a percent of total cases for that day. Only dates with more than 10 total cases are plotted.

MN
==========================================

Row 
---------------------------------------------------

### Cumulative Cases 

```{r MNtotal, echo=FALSE}
MN_total_plot <- COVID_states %>%
  filter(state %in% "MN") %>%
  ggplot(aes(x = date, y = positive)) + 
  geom_line(color = "blue") +
  geom_point(fill = "gray25", size = rel(2)) + 
  scale_y_log10(breaks = log_breaks(n = 7, base = 10),
                limits = c(1, 20000), 
                labels = scales::comma_format(accuracy = 1),
                expand = c(0, 0)) + 
  scale_x_date(date_breaks = "1 week", 
               minor_breaks = "1 day", date_labels = "%b %d") + 
  xlab("Date") + 
  ylab("Total Confirmed Cases")

MN_plotly_total <- ggplotly(p = (MN_total_plot + theme_classic(base_size = 15) + 
  theme(panel.grid.major.y = element_line(color = "gray80"))))

MN_plotly_total
```

> Note that total cases are plotted on a log scale.

### New Daily Cases

```{r MNdaily, echo=FALSE}
# average new daily cases
MN_new_daily_plot <- COVID_states %>%
  filter(state %in% "MN") %>%
  ggplot(aes(x = date, y = avgDailyPositives)) +
  geom_col(color = "black", fill = "gray50") + 
  scale_y_continuous(labels = comma,
                     limits = c(0, 250),
                     expand = c(0, 0)) +
  scale_x_date(date_breaks = "1 week", date_labels = "%b %d",
               minor_breaks = "1 day") +
  xlab("Date") + 
  ylab("Daily New Cases")

MN_plotly_new_daily <- ggplotly(
  p = (MN_new_daily_plot + 
         theme_classic(base_size = 15) + 
         theme(panel.grid.major.y = element_line(color = "gray85"))))

MN_plotly_new_daily
```

> The 5-day rolling average is plotted.

Row
--------------------------------------------------

### Daily Growth Factor 

```{r MNdailyGrowth, echo=FALSE}
MN_growth_rate_plot <- COVID_states %>%
  filter(state %in% "MN") %>%
  filter(avgDailyGrowth < 100) %>%
  ggplot(aes(x = date, y = avgDailyGrowth)) +
  geom_line(color = "blue") +
  geom_point(fill = "gray25", size = rel(2)) + 
  scale_x_date(date_breaks = "1 week", 
               minor_breaks = "1 day", date_labels = "%b %d") + 
  scale_y_continuous(breaks = seq(0, 2.5, by = 0.5),
                     limits = c(0, 2.6),
                     expand = c(0, 0)) +
  xlab("Date") + 
  ylab("Daily Growth Factor")

MN_growth_plotly <- ggplotly(
  p = (MN_growth_rate_plot + theme_classic(base_size = 15) +
  theme(panel.grid.major.y = element_line(color = "gray80"))))

MN_growth_plotly
```

> This is the factor by which new cases multiply each day. A growth factor less than 1 indicates declining growth. A growth factor greater than 1 indicates increasing, and possibly exponential, growth. The 5-day rolling average is plotted. 

### Percent Change in New Cases

```{r MNpercentChange, echo=FALSE}
# average daily percent change
MN_daily_percent <- COVID_states %>%
  filter(state %in% "MN") %>%
  filter(positive > 10) %>%
  ggplot(aes(x = date, y = percentChange)) +
  geom_col(color = "black", fill = "gray50") + 
  scale_y_continuous(labels = comma, limits = c(-25, 100),
                     expand = c(0, 0)) +
  scale_x_date(date_breaks = "1 week", date_labels = "%b %d",
               minor_breaks = "1 day") +
  xlab("Date") + 
  ylab("Percent change in cases")

MNpercentPlotly <- ggplotly(
  p = (
    MN_daily_percent + theme_classic(base_size = 15) + 
      theme(panel.grid.major.y = element_line(color = "gray85"))))

MNpercentPlotly
```

> Percent change is calculated as using the 5-day rolling average of daily new cases as a percent of total cases for that day. Only dates with more than 10 total cases are plotted.

AL
==========================================

Row 
---------------------------------------------------

### Cumulative Cases 

```{r ALtotal, echo=FALSE}
AL_total_plot <- COVID_states %>%
  filter(state %in% "AL") %>%
  ggplot(aes(x = date, y = positive)) + 
  geom_line(color = "blue") +
  geom_point(fill = "gray25", size = rel(2)) + 
  scale_y_log10(breaks = log_breaks(n = 7, base = 10),
                limits = c(1, 20000), 
                labels = scales::comma_format(accuracy = 1),
                expand = c(0, 0)) + 
  scale_x_date(date_breaks = "1 week", 
               minor_breaks = "1 day", date_labels = "%b %d") + 
  xlab("Date") + 
  ylab("Total Confirmed Cases")

AL_plotly_total <- ggplotly(p = (AL_total_plot + theme_classic(base_size = 15) + 
  theme(panel.grid.major.y = element_line(color = "gray80"))))

AL_plotly_total
```

> Note that total cases are plotted on a log scale.

### New Daily Cases

```{r ALdaily, echo=FALSE}
# average new daily cases
AL_new_daily_plot <- COVID_states %>%
  filter(state %in% "AL") %>%
  ggplot(aes(x = date, y = avgDailyPositives)) +
  geom_col(color = "black", fill = "gray50") + 
  scale_y_continuous(labels = comma,
                     limits = c(0, 330),
                     expand = c(0, 0)) +
  scale_x_date(date_breaks = "1 week", date_labels = "%b %d",
               minor_breaks = "1 day") +
  xlab("Date") + 
  ylab("Daily New Cases")

AL_plotly_new_daily <- ggplotly(
  p = (AL_new_daily_plot + 
         theme_classic(base_size = 15) + 
         theme(panel.grid.major.y = element_line(color = "gray85"))))

AL_plotly_new_daily
```

> The 5-day rolling average is plotted.

Row
--------------------------------------------------

### Daily Growth Factor 

```{r ALdailyGrowth, echo=FALSE}
AL_growth_rate_plot <- COVID_states %>%
  filter(state %in% "AL") %>%
  filter(avgDailyGrowth < 100) %>%
  ggplot(aes(x = date, y = avgDailyGrowth)) +
  geom_line(color = "blue") +
  geom_point(fill = "gray25", size = rel(2)) + 
  scale_x_date(date_breaks = "1 week", 
               minor_breaks = "1 day", date_labels = "%b %d") + 
  scale_y_continuous(breaks = seq(0, 2.5, by = 0.5),
                     limits = c(0, 2.6),
                     expand = c(0, 0)) +
  xlab("Date") + 
  ylab("Daily Growth Factor")

AL_growth_plotly <- ggplotly(
  p = (AL_growth_rate_plot + theme_classic(base_size = 15) +
  theme(panel.grid.major.y = element_line(color = "gray80"))))

AL_growth_plotly
```

> This is the factor by which new cases multiply each day. A growth factor less than 1 indicates declining growth. A growth factor greater than 1 indicates increasing, and possibly exponential, growth. The 5-day rolling average is plotted. 

### Percent Change in New Cases

```{r ALpercentChange, echo=FALSE}
# average daily percent change
AL_daily_percent <- COVID_states %>%
  filter(state %in% "AL") %>%
  filter(positive > 10) %>%
  ggplot(aes(x = date, y = percentChange)) +
  geom_col(color = "black", fill = "gray50") + 
  scale_y_continuous(labels = comma, limits = c(-25, 100),
                     expand = c(0, 0)) +
  scale_x_date(date_breaks = "1 week", date_labels = "%b %d",
               minor_breaks = "1 day") +
  xlab("Date") + 
  ylab("Percent change in cases")

ALpercentPlotly <- ggplotly(
  p = (
    AL_daily_percent + theme_classic(base_size = 15) + 
      theme(panel.grid.major.y = element_line(color = "gray85"))))

ALpercentPlotly
```

> Percent change is calculated as using the 5-day rolling average of daily new cases as a percent of total cases for that day. Only dates with more than 10 total cases are plotted.

MA
==========================================

Row 
---------------------------------------------------

### Cumulative Cases 

```{r MAtotal, echo=FALSE}
MA_total_plot <- COVID_states %>%
  filter(state %in% "MA") %>%
  ggplot(aes(x = date, y = positive)) + 
  geom_line(color = "blue") +
  geom_point(fill = "gray25", size = rel(2)) + 
  scale_y_log10(breaks = log_breaks(n = 7, base = 10),
                limits = c(1, 200000), 
                labels = scales::comma_format(accuracy = 1),
                expand = c(0, 0)) + 
  scale_x_date(date_breaks = "1 week", 
               minor_breaks = "1 day", date_labels = "%b %d") + 
  xlab("Date") + 
  ylab("Total Confirmed Cases")

MA_plotly_total <- ggplotly(p = (MA_total_plot + theme_classic(base_size = 15) + 
  theme(panel.grid.major.y = element_line(color = "gray80"))))

MA_plotly_total
```

> Note that total cases are plotted on a log scale.

### New Daily Cases

```{r MAdaily, echo=FALSE}
# average new daily cases
MA_new_daily_plot <- COVID_states %>%
  filter(state %in% "MA") %>%
  ggplot(aes(x = date, y = avgDailyPositives)) +
  geom_col(color = "black", fill = "gray50") + 
  scale_y_continuous(labels = comma,
                     limits = c(0, 2100),
                     expand = c(0, 0)) +
  scale_x_date(date_breaks = "1 week", date_labels = "%b %d",
               minor_breaks = "1 day") +
  xlab("Date") + 
  ylab("Daily New Cases")

MA_plotly_new_daily <- ggplotly(
  p = (MA_new_daily_plot + 
         theme_classic(base_size = 15) + 
         theme(panel.grid.major.y = element_line(color = "gray85"))))

MA_plotly_new_daily
```

> The 5-day rolling average is plotted.

Row
--------------------------------------------------

### Daily Growth Factor 

```{r MAdailyGrowth, echo=FALSE}
MA_growth_rate_plot <- COVID_states %>%
  filter(state %in% "MA") %>%
  filter(avgDailyGrowth < 100) %>%
  ggplot(aes(x = date, y = avgDailyGrowth)) +
  geom_line(color = "blue") +
  geom_point(fill = "gray25", size = rel(2)) + 
  scale_x_date(date_breaks = "1 week", 
               minor_breaks = "1 day", date_labels = "%b %d") + 
  scale_y_continuous(breaks = seq(0, 2.5, by = 0.5),
                     limits = c(0, 2.6),
                     expand = c(0, 0)) +
  xlab("Date") + 
  ylab("Daily Growth Factor")

MA_growth_plotly <- ggplotly(
  p = (MA_growth_rate_plot + theme_classic(base_size = 15) +
  theme(panel.grid.major.y = element_line(color = "gray80"))))

MA_growth_plotly
```

> This is the factor by which new cases multiply each day. A growth factor less than 1 indicates declining growth. A growth factor greater than 1 indicates increasing, and possibly exponential, growth. The 5-day rolling average is plotted. 

### Percent Change in New Cases

```{r MApercentChange, echo=FALSE}
# average daily percent change
MA_daily_percent <- COVID_states %>%
  filter(state %in% "MA") %>%
  filter(positive > 10) %>%
  ggplot(aes(x = date, y = percentChange)) +
  geom_col(color = "black", fill = "gray50") + 
  scale_y_continuous(labels = comma, limits = c(-25, 100),
                     expand = c(0, 0)) +
  scale_x_date(date_breaks = "1 week", date_labels = "%b %d",
               minor_breaks = "1 day") +
  xlab("Date") + 
  ylab("Percent change in cases")

MApercentPlotly <- ggplotly(
  p = (
    MA_daily_percent + theme_classic(base_size = 15) + 
      theme(panel.grid.major.y = element_line(color = "gray85"))))

MApercentPlotly
```

> Percent change is calculated as using the 5-day rolling average of daily new cases as a percent of total cases for that day. Only dates with more than 10 total cases are plotted.

NJ
==========================================

Row 
---------------------------------------------------

### Cumulative Cases 

```{r NJtotal, echo=FALSE}
NJ_total_plot <- COVID_states %>%
  filter(state %in% "NJ") %>%
  ggplot(aes(x = date, y = positive)) + 
  geom_line(color = "blue") +
  geom_point(fill = "gray25", size = rel(2)) + 
  scale_y_log10(breaks = log_breaks(n = 7, base = 10),
                limits = c(1, 200000), 
                labels = scales::comma_format(accuracy = 1),
                expand = c(0, 0)) + 
  scale_x_date(date_breaks = "1 week", 
               minor_breaks = "1 day", date_labels = "%b %d") + 
  xlab("Date") + 
  ylab("Total Confirmed Cases")

NJ_plotly_total <- ggplotly(p = (NJ_total_plot + theme_classic(base_size = 15) + 
  theme(panel.grid.major.y = element_line(color = "gray80"))))

NJ_plotly_total
```

> Note that total cases are plotted on a log scale.

### New Daily Cases

```{r NJdaily, echo=FALSE}
# average new daily cases
NJ_new_daily_plot <- COVID_states %>%
  filter(state %in% "NJ") %>%
  ggplot(aes(x = date, y = avgDailyPositives)) +
  geom_col(color = "black", fill = "gray50") + 
  scale_y_continuous(labels = comma,
                     limits = c(0, 5300),
                     expand = c(0, 0)) +
  scale_x_date(date_breaks = "1 week", date_labels = "%b %d",
               minor_breaks = "1 day") +
  xlab("Date") + 
  ylab("Daily New Cases")

NJ_plotly_new_daily <- ggplotly(
  p = (NJ_new_daily_plot + 
         theme_classic(base_size = 15) + 
         theme(panel.grid.major.y = element_line(color = "gray85"))))

NJ_plotly_new_daily
```

> The 5-day rolling average is plotted.

Row
--------------------------------------------------

### Daily Growth Factor 

```{r NJdailyGrowth, echo=FALSE}
NJ_growth_rate_plot <- COVID_states %>%
  filter(state %in% "NJ") %>%
  filter(avgDailyGrowth < 100) %>%
  ggplot(aes(x = date, y = avgDailyGrowth)) +
  geom_line(color = "blue") +
  geom_point(fill = "gray25", size = rel(2)) + 
  scale_x_date(date_breaks = "1 week", 
               minor_breaks = "1 day", date_labels = "%b %d") + 
  scale_y_continuous(breaks = seq(0, 2.5, by = 0.5),
                     limits = c(0, 2.6),
                     expand = c(0, 0)) +
  xlab("Date") + 
  ylab("Daily Growth Factor")

NJ_growth_plotly <- ggplotly(
  p = (NJ_growth_rate_plot + theme_classic(base_size = 15) +
  theme(panel.grid.major.y = element_line(color = "gray80"))))

NJ_growth_plotly
```

> This is the factor by which new cases multiply each day. A growth factor less than 1 indicates declining growth. A growth factor greater than 1 indicates increasing, and possibly exponential, growth. The 5-day rolling average is plotted. 

### Percent Change in New Cases

```{r NJpercentChange, echo=FALSE}
# average daily percent change
NJ_daily_percent <- COVID_states %>%
  filter(state %in% "NJ") %>%
  filter(positive > 10) %>%
  ggplot(aes(x = date, y = percentChange)) +
  geom_col(color = "black", fill = "gray50") + 
  scale_y_continuous(labels = comma, limits = c(-25, 100),
                     expand = c(0, 0)) +
  scale_x_date(date_breaks = "1 week", date_labels = "%b %d",
               minor_breaks = "1 day") +
  xlab("Date") + 
  ylab("Percent change in cases")

NJpercentPlotly <- ggplotly(
  p = (
    NJ_daily_percent + theme_classic(base_size = 15) + 
      theme(panel.grid.major.y = element_line(color = "gray85"))))

NJpercentPlotly
```

> Percent change is calculated as using the 5-day rolling average of daily new cases as a percent of total cases for that day. Only dates with more than 10 total cases are plotted.